#define _CRT_SECURE_NO_WARNINGS
#include"lian.h"
void SLprintf(SL* lu)
{
	SL* arr = lu->xia;
	while (arr != lu)
	{
		printf("%d->", arr->shu);
		arr = arr->xia;
	}
	printf(" \n");
}
SL* xin(leixing x)
{
	SL* arr = (SL*)malloc(sizeof(SL));
	if (arr == NULL)
	{
		perror("malloc arr");
		exit(1);
	}
	arr->shu = x;
	arr->shang = arr->xia = arr;
	return arr;
}
void SLinit(SL** lu)
{
	*lu = xin(-1);
}
void SLwiecha(SL* lu, leixing x)
{
	assert(lu);
	SL* arr = xin(x);
	arr->shang = lu->shang;
	arr->xia = lu;
	lu->shang->xia = arr;
	lu->shang = arr;
}
void SLtoucha(SL* lu, leixing x)
{
	assert(lu);
	SL* arr = xin(x);
	arr->shang = lu;
	arr->xia = lu->xia;
	lu->xia->shang = arr;
	lu->xia = arr;
}
void SLweixiao(SL* lu)
{
	assert(lu);
	SL* arr = lu->shang;
	arr->shang->xia = lu;
	lu->shang = arr->shang;
	free(arr);
	arr = NULL;
}
void SLtouxiao(SL* lu)
{
	assert(lu);
	SL* arr = lu->xia;
	arr->xia->shang = lu;
	lu->xia = arr->xia;
	free(arr);
	arr = NULL;
}
SL* SLchazhao(SL* lu, leixing x)
{
	SL* arr = lu->xia;
	while (arr != lu)
	{
		if (arr->shu == x)
		{
			return arr;
		}
		arr = arr->xia;
	}
	return NULL;
}
void SLHzhicha(SL* zhi, leixing x)
{
	assert(zhi);
	SL* arr = xin(x);
	arr->shang = zhi;
	arr->xia =zhi->xia ;
	zhi->xia->shang = arr;
	zhi->xia = arr; 
}
void zhixiao(SL* zhi)
{
	assert(zhi);
	zhi->shang->xia = zhi->xia;
	zhi->xia->shang = zhi->shang;
	free(zhi);
	zhi = NULL;
}
void SLQzhicha(SL* zhi, leixing x)
{
	assert(zhi);
	SL* arr = xin(x);
	arr->shang = zhi->shang;
	arr->xia = zhi;
	zhi->shang->xia = arr;
	zhi->shang = arr;
}
void SLxiao(SL* lu)
{
	assert(lu);
	SL* arr = lu->xia;
	while (arr != lu)
	{
		SL* xin = arr->xia;
		free(arr);
		arr = xin;
	}
	free(lu);
	lu = NULL;
}